import LevelBaseControl from "../LevelCommon/LevelBaseControl";
import MoveObj from "../Prefabs/InteractivObj/Common/MoveObj";
import RotateObj from "../Prefabs/InteractivObj/Common/RotateObj";
import RotateCommon from "../Prefabs/InteractivObj/Common/RotateCommon";
import { GamePropData } from "../Data/GamePropData";
import Gate from "../Prefabs/InteractivObj/Gate";
import DialogDataConst from "../../constant/DialogDataConst";
import GamePropConst from "../../constant/GamePropConst";
import EventNameList from "../../constant/EventNameList";

export default class LevelControl10 extends LevelBaseControl {

    /** 冰柜门1*/
    private fridgeGate1: MoveObj;
    /** 冰柜门2*/
    private fridgeGate2: MoveObj;
    /** 握着的手的链子*/
    private holdLianZi: Laya.Sprite3D;
    /** 张开手的链子*/
    private openLianZi: Laya.Sprite3D;
    /** 张开的手*/
    private openHand: RotateObj;
    /** 微波炉控制器*/
    private weiboController: RotateCommon;
    /** 微波炉控制器 冷index*/
    private coldWeiBoIndex: number = 5;
    /** 微波炉控制器 热index*/
    private hotWeiBoIndex: number = 1;
    /** 当前微波炉里放的东西*/
    private curWeiBoProp: GamePropData;
    /** 微波炉下面的蛋糕印记里的蛋糕*/
    private cake: Laya.Sprite3D;
    /** 微波炉下面盒子的门*/
    private weiboBottomGate: RotateObj;
    /** 密码锁*/
    private passwordLock: RotateObj;
    /** 最后的门*/
    private endGate: Gate;
    /** 加热后的披萨*/
    private hotPizza: Laya.Sprite3D;
    /** 存本地是否看过结束视频了*/
    public IS_HAVE_SEE_END: string = "IS_HAVE_SEE_END";
    //  bool IsHaveSeeEnd
    //  {
    //      get
    //      {
    //          return PlayerPrefsTool.GetBool(IS_HAVE_SEE_END,false);
    //      }
    //      set
    //      {
    //          PlayerPrefsTool.SetBool(IS_HAVE_SEE_END, value);
    //      }
    //  }

    protected startByBase() {
        let room1 = this.allLevelObjs[0].owner;
        let walls = room1.getChildByName("walls");
        let wall1 = walls.getChildByName("wall1");
        let wall3 = walls.getChildByName("wall3");
        let wall4 = walls.getChildByName("wall4");

        this.fridgeGate1 = wall3.getChildByName("SM_Prop_Bookshelf_02").getChildByName("SM_Bld_House_RanchSlider_01").getChildByName("focus")
            .getChildByName("fridgeGate1").getComponent(MoveObj);

        this.fridgeGate2 = wall3.getChildByName("SM_Prop_Bookshelf_02").getChildByName("SM_Bld_House_RanchSlider_01").getChildByName("focus")
            .getChildByName("fridgeGate2").getComponent(MoveObj);

        this.weiboController = wall4.getChildByName("focus").getChildByName("controller").getComponent(RotateCommon);

        this.cake = wall4.getChildByName("focus").getChildByName("cake") as Laya.Sprite3D;

        this.weiboBottomGate = wall4.getChildByName("focus").getChildByName("weiboBox").getChildByName("gate").getComponent(RotateObj);

        this.holdLianZi = wall3.getChildByName("SM_Prop_Bookshelf_02").getChildByName("SM_Bld_House_RanchSlider_01").getChildByName("focus")
            .getChildByName("hold_lianzi") as Laya.Sprite3D;

        this.openLianZi = wall4.getChildByName("ChamferBox001").getChildByName("handFocus").getChildByName("openLianZi") as Laya.Sprite3D;


        this.openHand = wall4.getChildByName("ChamferBox001").getChildByName("handFocus").getChildByName("openHand").getComponent(RotateObj);

        this.passwordLock = wall1.getChildByName("gateLockFocus").getChildByName("passWordLock").getComponent(RotateObj);

        this.endGate = wall1.getChildByName("endGate").getComponent(Gate);

        this.hotPizza = wall4.getChildByName("focus").getChildByName("hotPiza") as Laya.Sprite3D;

    }
    public DoInteractObjLogic(_name: string): boolean {
        switch (_name) {
            /** 打开第一个柜子门*/
            case "arrowLock1_ArrowUnlocked":
                this.fridgeGate1.Interactive();
                break;
            /** 打开第二个柜子门*/
            case "arrowLock2_ArrowUnlocked":
                this.fridgeGate2.Interactive();
                break;
            /** 火烈鸟提示*/
            case "fireBird":
                this.ShowDialog(DialogDataConst.fire_bird);
                break;
            /** 握紧的手 链子  判断有没有钥匙 有就解开*/
            case "hold_lianzi":
                if (this.IsSelectProp(GamePropConst.RED_KEY)) {
                    this.holdLianZi.active = false;
                }
                break;
            /** 张开的手 链子  判断有没有钥匙 有就解开*/
            case "openLianZi":
                if (this.IsSelectProp(GamePropConst.RED_KEY)) {
                    this.openLianZi.active = false;
                    this.openHand.Interactive();
                }
                break;
            /** 张开的手 聚焦*/
            case "openHand_focus":
                if (this.openHand.IsMoving() || this.openLianZi.activeInHierarchy) {
                    return false;
                }
                break;
            /** 握紧的手 如果链子拿掉了 就可以获得*/
            case "hand_hold":
                if (this.holdLianZi.activeInHierarchy) {
                    this.ShowDialog(DialogDataConst.unable_take_out);
                    return false;
                }
                break;
            /** 点击微波炉*/
            case "weibolu":
                if (this.IsSelectProp(GamePropConst.Mould_with_baking_water)) {
                    if (this.curWeiBoProp == null) {
                        this.curWeiBoProp = this.CurSelectProp;
                        this.UseCurProp();
                        this.JudgeWeiBo();
                    }
                    else {
                        this.ShowDialog(DialogDataConst.weibo_be_stand);
                    }
                }
                /** 手加热 得到张开手掌的手*/
                else if (this.IsSelectProp(GamePropConst.hold_hand)) {
                    if (this.curWeiBoProp == null) {
                        this.curWeiBoProp = this.CurSelectProp;
                        this.UseCurProp();
                        this.JudgeWeiBo();
                    }
                    else {
                        this.ShowDialog(DialogDataConst.weibo_be_stand);
                    }
                }
                /** 加热披萨*/
                else if (this.IsSelectProp(GamePropConst.pissa_prop)) {
                    if (this.curWeiBoProp == null) {
                        this.curWeiBoProp = this.CurSelectProp;
                        this.UseCurProp();
                        this.JudgeWeiBo();
                    }
                    else {
                        this.ShowDialog(DialogDataConst.weibo_be_stand);
                    }
                }
                else {

                }
                break;
            /** 解锁了物理锁 获得模具*/
            case "physLock_UnLock":
                this.GetGamePropById(GamePropConst.Mould_prop);
                break;
            /** 密码锁打开了*/
            case "passWordLock":
                this.passwordLock.Interactive();
                break;
            /** 点击手印 判断手掌道具  有的话 就开门了*/
            case "handLock":
                if (this.IsSelectProp(GamePropConst.open_hand)) {
                    this.UseCurProp();

                    let handler1 = (obj: any) => {
                        this.endGate.SetOpen();
                        window.gameFacade.EventMng.remove(EventNameList.CameraResetPosEvent, this, handler1)
                    };
                    window.gameFacade.EventMng.add(EventNameList.CameraResetPosEvent, this, handler1);
                    this.ShowDialog(DialogDataConst.open_gate);
                }
                break;
            /** 旋转了微波炉控制器*/
            case "controller_Rotate":
                this.JudgeWeiBo();
                break;
            /** 点击了微波炉下的box 判断*/
            case "weiboBox":
                /** 调节器没放上 先判断有没有选择这个道具 并放上去*/
                if (!this.weiboController.owner.activeInHierarchy) {
                    if (this.IsSelectProp(GamePropConst.weibo_controller)) {
                        this.UseCurProp();
                        this.weiboController.owner.active = true;
                    }
                }
                /** 判断有没有蛋糕 有就放上去 并打开下面的门*/
                else {
                    if (this.IsSelectProp(GamePropConst.Cake_pieces)) {
                        this.UseCurProp();
                        this.cake.active = true
                        this.weiboBottomGate.Interactive();
                    }
                }
                break;
            /** 进入最终的门  过关*/
            case "endGate_In_Gate":
                /** 没看过视频 看*/
                //  if (!IsHaveSeeEnd)
                //  {
                //      AudioManager.Instance.StopUnVariVoice(AudioManager.BGM_IN);
                //      Action handler = () =>
                //      {
                //          IsHaveSeeEnd = true;
                //          FinishLevel();
                //      };
                //      UIClass uiClass = UIManager.Instance.CreateUI(UIType.VideoPanel);
                //      uiClass.uiBase.GetComponent<VideoPanel>().SetData(VideoDataConst.END_VIDEO, handler);
                //  }
                //  else
                {
                    this.FinishLevel();
                }
                break;
            default:
                break;
        }
        return true;
    }
    /** 判断微波炉结果*/
    private JudgeWeiBo() {
        if (this.curWeiBoProp != null && this.curWeiBoProp.id == GamePropConst.Mould_with_baking_water) {
            if (this.weiboController.curIndex == this.coldWeiBoIndex) {
                /** 获得蛋糕块*/
                this.GetGamePropById(GamePropConst.Cake_pieces);
                this.curWeiBoProp = null;
            }
            else if (this.weiboController.curIndex == this.hotWeiBoIndex) {
                this.ShowDialog(DialogDataConst.nothing_happened);
            }
            else {

            }
        }
        if (this.curWeiBoProp != null && this.curWeiBoProp.id == GamePropConst.hold_hand) {
            if (this.weiboController.curIndex == this.hotWeiBoIndex) {
                /** 获得蛋糕块*/
                this.GetGamePropById(GamePropConst.open_hand);
                this.curWeiBoProp = null;
            }
            else if (this.weiboController.curIndex == this.coldWeiBoIndex) {
                this.ShowDialog(DialogDataConst.nothing_happened);
            }
            else {

            }
        }
        if (this.curWeiBoProp != null && this.curWeiBoProp.id == GamePropConst.pissa_prop) {
            if (this.weiboController.curIndex == this.hotWeiBoIndex) {
                /** 显示加热后的披萨*/
                this.hotPizza.active = true;
                this.curWeiBoProp = null;
            }
            else if (this.weiboController.curIndex == this.coldWeiBoIndex) {
                this.ShowDialog(DialogDataConst.nothing_happened);
            }
            else {

            }
        }
    }
}